package com.bajiao.app.controller.index;

import com.bajiao.app.base.AppBaseController;
import com.bajiao.common.api.vo.RestResult;
import com.bajiao.entity.agreement.Agreement;
import com.bajiao.entity.banner.Banner;
import com.bajiao.entity.coupon.Coupon;
import com.bajiao.entity.industry.Industry;
import com.bajiao.entity.message.Message;
import com.bajiao.service.agreement.AgreementService;
import com.bajiao.service.banner.BannerService;
import com.bajiao.service.config.ConfigService;
import com.bajiao.service.coupon.CouponService;
import com.bajiao.service.industry.IndustryService;
import com.bajiao.service.message.MessageService;
import com.bajiao.vo.config.ConfigVO;
import com.bajiao.vo.coupon.CouponResponse;
import com.bajiao.vo.index.IndexResponse;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "首页接口")
@RestController
@RequestMapping("/api/v1/index")
public class RestIndexController extends AppBaseController {

    @Resource
    private BannerService bannerService;
    @Resource
    private IndustryService industryService;
    @Resource
    private MessageService messageService;
    @Resource
    private CouponService couponService;
    @Resource
    private AgreementService agreementService;
    @Resource
    private ConfigService configService;

    @GetMapping(value = "/home")
    @ApiOperation(value = "首页数据")
    public RestResult<IndexResponse> getIndexHome(@ModelAttribute("userId") String userId) {
        //@create by FanJq 2024/12/12 15:48 轮播图列表
        List<Banner> bannerList = bannerService.getList();
        //@create by FanJq 2024/12/12 15:48 行业列表
        List<Industry> industryList = industryService.getList();
        //@create by FanJq 2024/12/12 15:48 最新公告列表
        List<Message> messageList = messageService.getLatest(5);
        //@create by FanJq 2024/12/12 15:48 推荐优惠券列表
        List<CouponResponse> couponList = couponService.getIndexList(userId, 10);
        //@create by FanJq 2024/12/12 15:49 组装返回数据
        IndexResponse response = new IndexResponse(bannerList, industryList, messageList, couponList);
        return success(response);
    }

    @GetMapping(value = "/agreement")
    @ApiOperation(value = "获取协议")
    @ApiImplicitParam(name = "code", value = "merchant-商家合作协议 <br/> user-用户协议 <br/> privacy-隐私政策", dataType = "String", required = true)
    public RestResult<Agreement> getAgreement(@RequestParam("code") String code) {
        Agreement agreement = agreementService.getByCode(code);
        return success(agreement);
    }

    @GetMapping(value = "/aboutUs")
    @ApiOperation(value = "关于平台")
    public RestResult<Agreement> getAboutUs() {
        Map result = configService.queryNameAndValueByGroup("aboutUs");
        return success(result);
    }
}
